package com.test.practice.socket.udp;

import lombok.Cleanup;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

/**
 * Udp服务端
 *
 * @Description: Udp服务端
 * =======================
 * @Author: Jovi
 * =======================
 * @Date: Created in 2023-02-10
 * =======================
 * @Version: 1.1.2.0
 */
public class UdpServerDemo {

    public static void main(String[] args) throws Exception {

        @Cleanup DatagramSocket ds = new DatagramSocket(9090);

        byte[] datas = new byte[1024];

        DatagramPacket dp = new DatagramPacket(
                datas,
                0,
                datas.length);

        ds.receive(dp);

        System.out.println(
                new String(
                        dp.getData(),
                        0,
                        dp.getLength()));
    }
}
